Type HTMLImageElement.crossOrigin as a literal union of known CORS values - #64179
Draft
Ryan Cavanaugh (RyanCavanaugh) with Copilot wants to merge 3 commits into
Draft
Type HTMLImageElement.crossOrigin as a literal union of known CORS values#64179Ryan Cavanaugh (RyanCavanaugh) with Copilot wants to merge 3 commits into
Ryan Cavanaugh (RyanCavanaugh) with Copilot wants to merge 3 commits into
Conversation
Copilot started work on behalf of
Ryan Cavanaugh (RyanCavanaugh)
September 5, 2026 07:22
View session
Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix crossOrigin type to use literal union
Type HTMLImageElement.crossOrigin as a literal union of known CORS values
Sep 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
HTMLImageElement.crossOriginwas declared asstring | null, so invalid values type-checked:The HTML spec defines it as reflecting
crossoriginlimited to only known values —anonymousanduse-credentials, with the empty string mapping toanonymous.Changes
lib.dom.d.ts:crossOrigin: string | null→crossOrigin: "anonymous" | "use-credentials" | "" | nullonHTMLImageElement.nullis retained (assigning it removes the attribute; the getter returnsnullwhen absent);""is retained as a valid author value (<img crossorigin>). This matches the existingdecoding: "async" | "sync" | "auto"pattern in the same interface.htmlImageElementCrossOrigin.ts: new compiler test covering each valid assignment, the invalid one, and reading the property into the literal union. Committed in its failing state first, so the baseline diff shows the behavior change.Notes for reviewers
Two open questions:
tsc/internal/bundled/README.mdstates the DOM libs aren't meant to be hand-edited and that changes belong in TypeScript-DOM-lib-generator. This edit will be lost on regeneration unless mirrored upstream — treat it as the desired outcome rather than the durable fix.HTMLImageElementto match the issue, leavingHTMLScriptElement,HTMLLinkElement,HTMLMediaElement, andSVGImageElementasstring | null. It's also breaking for code assigning a plainstring(e.g. fromgetAttribute), which now needs narrowing or a cast. Since the setter accepts arbitrary strings at runtime, this is an authoring-surface improvement rather than a reflection of runtime behavior.No compiler code changed; the full suite showed no baseline fallout beyond the new test.